home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
c
/
compcomp
/
os2yacc
/
ywract.3c
< prev
next >
Wrap
Text File
|
1989-09-29
|
3KB
|
102 lines
/*
HEADER: CUG nnn.nn;
TITLE: YACC - Yet Another Compilier-Compilier
VERSION: 1.0 for IBM-PC
DATE: JAN 28, 1985
DESCRIPTION: LALR(1) Parser Generator. From UNIX
KEYWORDS: Parser Generator Compilier-Compilier YACC
SYSTEM: IBM-PC and Compatiables
FILENAME: YWRACT.3C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: LEX and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: DESMET-C
REFERENCES: UNIX Systems Manuals
*/
#include "y3.h"
void wract( int i )
{
/* output state i */
/* temp1 has the actions, lastred the default */
int p, p0, p1;
int ntimes, tred, count, j;
int flag;
/* find the best choice for lastred */
lastred = 0;
ntimes = 0;
TLOOP(j)
{
if( temp1[j] >= 0 ) continue;
if( temp1[j]+lastred == 0 ) continue;
/* count the number of appearances of temp1[j] */
count = 0;
tred = -temp1[j];
levprd[tred] |= REDFLAG;
TLOOP(p)
{
if( temp1[p]+tred == 0 ) ++count;
}
if( count >ntimes )
{
lastred = tred;
ntimes = count;
}
}
/* for error recovery, arrange that, if there is a shift on the
/* error recovery token, `error', that the default be the error action */
if( temp1[1] > 0 ) lastred = 0;
/* clear out entries in temp1 which equal lastred */
TLOOP(p) if( temp1[p]+lastred == 0 )temp1[p]=0;
wrstate(i);
defact[i] = lastred;
flag = 0;
TLOOP(p0)
{
if( (p1=temp1[p0])!=0 )
{
if( p1 < 0 )
{
p1 = -p1;
goto exc;
}
else if( p1 == ACCEPTCODE )
{
p1 = -1;
goto exc;
}
else if( p1 == ERRCODE )
{
p1 = 0;
goto exc;
exc:
if( flag++ == 0 ) fprintf( ftable, "-1, %d,\n", i );
fprintf( ftable, "\t%d, %d,\n", tokset[p0].value, p1 );
++zzexcp;
}
else
{
fprintf( ftemp, "%d,%d,", tokset[p0].value, p1 );
++zzacent;
}
}
}
if( flag )
{
defact[i] = -2;
fprintf( ftable, "\t-2, %d,\n", lastred );
}
fprintf( ftemp, "\n" );
return;
}